<%@ page language="java" import="java.util.*"  pageEncoding="utf-8"%>
<%@include file="common/tag.jsp"%>
<c:set var="CTX" value="${pageContext.request.contextPath}" />
<%@include file="common/indexhead.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
    
    <title>部门新增页</title>
    </head>
  <style>
  .panel .panel-heading button {
  	padding: ;
	margin-left: ;
	background-color: ;
	border: ;
	outline: ;
  }
  </style>
 <body>
<div class="panel panel-primary">
	<div class="panel-heading">
		<div>
			<h3 class="panel-title">部门新增页</h3>
		</div>
		<div class="button"
			style="float: right;margin-top: -27px;margin-right: 5px;">
			<a class="btn btn-info" href="#" onclick="javascript:window.close();"><i class="fa fa-sign-out"></i>退出</a>
		</div>
		<div class="button"
			style="float: right;margin-top: -27px;margin-right: 5px;">
			<div class="btn btn-info"   onclick="tijiao()" href=""><i class="fa fa-check"></i>保存</div>
		</div>
	</div>
	<div class="panel-body" style="height:87%">

		<!-- <form modelAttribute="User"    id="userdetail" action="/user/update" method="POST" class="form-horizontal" -->
			<form   id="userdetail"  class="form-horizontal"
			style="width:90%;margin-top: 50px;">
			<fieldset>
				<div class="form-group">
					<label class="col-sm-2 control-label">部门名称</label>
					<div class="col-sm-4">
						<input class="form-control" id="deptName" name="deptName" type="text"/>
						<a id="create-user">选择</a>
					</div>
					<label class="col-sm-2 control-label">部门编号</label>
					<div class="col-sm-4">
						<input class="form-control" id="deptNumber" name="deptNumber" type="text"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">上级部门</label>
					<div class="col-sm-4">
						<input class="form-control" id="topId" name="topId" type="text"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">备注</label>
					<div class="col-sm-10">
						<textarea class="form-control" id="deptContent" name="deptContent" type="text"></textarea>
					</div>
				</div>
			</fieldset>
		</form>
		<hr></hr>
	</div>
</div>
<!-- 弹出框重写 -->

<div id="ycf-alert" class="modal">
      <div class="modal-dialog modal-sm">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
            <h5 class="modal-title"><i class="fa fa-exclamation-circle"></i> [Title]</h5>
          </div>
          <div class="modal-body small">
            <p>[Message]</p>
          </div>
          <div class="modal-footer" >
            <button type="button" class="btn btn-primary ok" data-dismiss="modal">[BtnOk]</button>
            <button type="button" class="btn btn-default cancel" data-dismiss="modal">[BtnCancel]</button>
          </div>
        </div>
      </div>
    </div>
<!-- 弹出框重写end -->
<%@include file="common/indexbottom.jsp"%>
<script
	src="${pageContext.request.contextPath}/mystyle/dialog/jquery-ui-1.10.4.custom.js"></script>
	<script
	src="${pageContext.request.contextPath}/mystyle/dialog/jquery-ui-1.10.4.custom.min.js"></script>
 

<script type="text/javascript">
/*  Modal.confirm(
{
    msg: "是否删除角色？"
}) 
Modal.alert(
            {
                msg: res['msg'],
                title: '操作',
                btnok: '确定',
                btncl:'取消'
            });*/
$(function() {
	$( ".mydate" ).datepicker();
window.Modal = function() {
    var reg = new RegExp("\\[([^\\[\\]]*?)\\]", 'igm');
    var alr = $("#ycf-alert");
    var ahtml = alr.html();

    //关闭时恢复 modal html 原样，供下次调用时 replace 用
    //var _init = function () {
    //alr.on("hidden.bs.modal", function (e) {
    //  $(this).html(ahtml);
    //});
    //}();
    /* html 复原不在 _init() 里面做了，重复调用时会有问题，直接在 _alert/_confirm 里面做 */

    var _alert = function(options) {
        alr.html(ahtml); // 复原
        alr.find('.ok').removeClass('btn-success').addClass('btn-primary');
        alr.find('.cancel').hide();
        _dialog(options);

        return {
            on: function(callback) {
                if (callback && callback instanceof Function) {
                    alr.find('.ok').click(function() {
                        callback(true)
                    });
                }
            }
        };
    };

    var _confirm = function(options) {
        alr.html(ahtml); // 复原
        alr.find('.ok').removeClass('btn-primary').addClass('btn-success');
        alr.find('.cancel').show();
        _dialog(options);

        return {
            on: function(callback) {
                if (callback && callback instanceof Function) {
                    alr.find('.ok').click(function() {
                        callback(true)
                    });

                }
            }
        };
    };

    var _dialog = function(options) {
        var ops = {
            msg: "提示内容",
            title: "操作提示",
            btnok: "确定",
            btncl: "取消"
        };

        $.extend(ops, options);

        console.log(alr);

        var html = alr.html().replace(reg,
        function(node, key) {
            return {
                Title: ops.title,
                Message: ops.msg,
                BtnOk: ops.btnok,
                BtnCancel: ops.btncl
            } [key];
        });

        alr.html(html);
        alr.modal({
            width: 500,
            backdrop: 'static'
        });
    }

    return {
        alert: _alert,
        confirm: _confirm
    }

} ();
});

function tijiao() {
Modal.confirm({
    msg: "是否新增部门？"
}).on(function(e) {
    var deptName = $("#deptName").val();
    var deptNumber = $("#deptNumber").val();
    var topId = $("#topId").val();
    var deptContent = $("#deptContent").val();
    $.ajax({
        type: "post",
        url: yongan.URL.deptAdd(),
        dataType: "json",
        data: {
            deptName: deptName,
            deptNumber: deptNumber,
            topId: topId,
            deptContent: deptContent
        },
        success: function(data) {

            if (data['success']) {
                Modal.alert({
                    msg: data['data']['stateinfo'],
                    title: '执行结果',
                    btnok: '确定',
                    btncl: '取消'
                }).on(function(e) {
                    window.close();
                });
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
            alert(textStatus);
            alert(errorThrown);
        }
    });
});
}
</script>
  </body>
</html>